/*
Kakine
ActionScript Framework
Copyright © 2011, PUNY, LLC.

This file is part of KAKINE.

KAKINE is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

KAKINE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with KAKINE.  If not, see <http://www.gnu.org/licenses/>.
*/ 
package com.puny.mvc.helpers {
	
	
	internal class HelperState
	{
		private var _handler:IContextHandler;
		private var _initialState:HelperState;
		private var _loopState:HelperState;
		private var _pauseState:HelperState;
		protected const CANCELED:HelperEvent = new HelperEvent(HelperEvent.CANCELED);
		protected const PAUSED:HelperEvent = new HelperEvent(HelperEvent.PAUSED);
		protected const RESUMED:HelperEvent = new HelperEvent(HelperEvent.RESUMED);
		protected const REVERTED:HelperEvent = new HelperEvent(HelperEvent.REVERTED);
		protected const SKIPPED:HelperEvent = new HelperEvent(HelperEvent.SKIPPED);
		protected const STARTED:HelperEvent = new HelperEvent(HelperEvent.STARTED);

		public function HelperState() {
		}

		public function initialize(handler:IContextHandler,initial:HelperState,loop:HelperState,pause:HelperState):void {
			_handler = handler;
			_initialState = initial;
			_loopState = loop;
			_pauseState = pause;
		}
		
		public function get initialState():HelperState {
			return _initialState;
		} 
		
		public function get loopState():HelperState {
			return _loopState;
		}
		
		public function get pauseState():HelperState {
			return _pauseState;
		}
		
		protected function get handler():IContextHandler {
			return _handler;
		}

		public function start():HelperState {return this;}
		public function pause():HelperState {return this;}
		public function cancel():HelperState {
			handler.dispatch(CANCELED);
			return this;
		}
		public function resume():HelperState {return this;}
		public function skip():HelperState {return this;}
		public function revert():HelperState {
			handler.before();
			handler.dispatch(REVERTED);
			return initialState;
		}
		public function cleanUp():HelperState {
			return null;
		}
	}
}